<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function ajax(url) {
            return new Promise(function(resolve, reject) {
                var xhr = new XMLHttpRequest();
                xhr.open("GET", url, true);
                xhr.send();
                xhr.onreadystatechange = function() {
                    if (xhr.readyState == 4) {
                        if (xhr.status == 200) {
                            resolve(xhr.responseText)
                        } else {
                            reject("出错了---")
                        }
                    }
                }
            })
        }





        /*
                ajax("./data/01.json")
                .then(
                    (d)=>{ 
                        console.log(d) 
                        return  ajax("./data/02.json")
                    }
                )
                .then( 
                    (d)=>{
                        console.log(d) 
                    }
                )
                .catch( 
                    (d)=>{
                        console.log(d);
                    }
                 )
        */

        // async await 是 generator 的语法糖





        async function getList() {
            try {
                let a = await ajax("./data/1.json");
                let b = await ajax("./data/2.json");
                console.log(a, b);
            } catch {
                console.log("try 中的 出错了，执行catch这的代码");
            }

        }
        getList();
    </script>
</body>

</html>